import ResMgr from "../Managers/ResMgr";


const {ccclass, property} = cc._decorator;

@ccclass
export default class Bullet extends cc.Component 
{
    private m_speed:number = 400;
    onLoad () 
    {

    }

    start () 
    {
        this.initViews();
    }




    private initViews():void
    {
        var texture2d = ResMgr.Instance.getAsset("Bullet","1");
        this.node.getComponent(cc.Sprite).spriteFrame.setTexture(texture2d);
        this.node.setContentSize(cc.size(texture2d.width,texture2d.height));
    }


    public setAngle(angle):void
    {
        this.node.angle = angle - 90;
    }


    update (dt) 
    {


        var radian = cc.misc.degreesToRadians(this.node.angle + 90);
        var movedis = dt * this.m_speed;
        var moveDir:any = {};
        moveDir.x = Math.cos(radian) * movedis;
        moveDir.y = Math.sin(radian) * movedis;
        var pos:any = new cc.Vec2(this.node.x + moveDir.x,this.node.y + moveDir.y);
        // this.node.position = pos;
        this.node.setPosition(pos);
    }


    
　　onCollisionEnter(other,self):void
    {
        // cc.log("onCollisionEneter>>>>>");

        
        this.node.destroy();

    }

    //=> 当两物体刚发生碰撞时被触发
　　onCollisionStay(other,self):void
    {

    }

    //=> 当两物体发生碰撞后，并且有交集的时候被触发
　　onCollisionExit(other,self):void
    {

    }

}
